<?php
$section = "update_login";

$titre = _LB_ACCOUNT_MANAGEMENT;
$smarty->assign('titre', $titre);

$act = Request::getIntNumber('act');
$annonceur_id = Request::getIntNumber('annonceur_id');

if ($_SESSION["is_agent"])
	if ($annonceur_id==0)
		$annonceur_id = $_SESSION["agentID"];

$login = new Login();

if (isset($_SESSION["userID"]) && $_SESSION["agentID"]!=0)
{
	$login->getFromAnnonceurId($_SESSION["userID"], $_SESSION["agentID"]);
}
else if (isset($_SESSION["userID"]))
{
	$login->getFromAnnonceurId($_SESSION["userID"], $_SESSION["annonceurID"]);
}

$missing = false;
if (!textvalid(trim($login->NOM)))
{
	$error_msg->add(_LB_NAME_IS_EMPTY);
	$missing = true;
}
else if (!Utils::isValidLength($login->NOM, MAX_LENGTH_NAME))
{
	$error_msg->add(_LB_NAME_IS_TOO_LONG);
	$missing = true;
}

if ($missing == true)
{
	$smarty->assign("is_missing", true);
}

$link_retour = get_link_retour_4_redirect("login","list/?");

if ($act == ACT_VALID_EDIT)
{
	$login->EMAIL = Request::get("EMAIL");
	$login->NOM = Request::get("NOM");
	$login->PRENOM = Request::get("PRENOM");
	$login->FONCTION = Request::get("FONCTION");
	$login->FAX = Request::get("FAX");
	$login->store();
	if ($login->PRENOM=="" && $login->NOM=="" )
		$_SESSION["is_update"] = TRUE;
	else
		$_SESSION["is_update"] = FALSE;
	redirect(APPLICATION_URL."/home/list");
}

$link_retour = get_link_retour_4_redirect("update_login",APPLICATION_URL. "/user/list/?");
$cfer = new Cfer(array(
	_LB_ACCUEIL => Utils::getHomeLink(),
	_LB_EDIT_ACCOUNT  => $link_retour));

$smarty->assign("cfer", $cfer);
$smarty->assign("login", $login);
$smarty->assign("annonceur_id",$login->ID_ANNONCEUR);
$smarty->assign("is_regie",0);
$smarty->assign("lb_head", _LB_EDIT_ACCOUNT);
$smarty->display('user_myaccount_form.html');